$(document).ready(function () {
    $("#zipCode").focus(function () {
        var currentValue = $(this).val();
        if (currentValue === 'Zipcode') {
            $(this).val("");
        }
    });
    $("#zipCode").blur(function () {
        var currentValue = $(this).val();
        if (currentValue === '') {
            $(this).val("Zipcode");
        }
    });

    $("#dlname").focus(function () {
        var currentValue = $(this).val();
        if (currentValue === 'Optional') {
            $(this).val("");
        }
    });
    $("#dlname").blur(function () {
        var currentValue = $(this).val();
        if (currentValue === '') {
            $(this).val("Optional");
        }
    });

    $("#dfname").focus(function () {
        var currentValue = $(this).val();
        if (currentValue === 'Optional') {
            $(this).val("");
        }
    });
    $("#dfname").blur(function () {
        var currentValue = $(this).val();
        if (currentValue === '') {
            $(this).val("Optional");
        }
    });

    $('span.ProviderName').each(function () {
        $(this).qtip({
            content: {
                text: $(this).next('.tooltiptext')
            }
        });
    });
});

function submitSearchProviderForm() {
    var zipCode = $("#zipCode").val();
    if (zipCode != 'Zipcode') {
        if (zipCode == "" || $.trim(zipCode).length < 5) {
            alert("ZipCode is not valid.");
            return false;
        }
    }

    document.getElementById('ldimg').style.display = 'block';
    submitFormWithSorting(1);
}
function submitFormWithSorting(colIndex) {
    var sortDirection = getParameterByName("direction");
    if (typeof (sortDirection) == "undefined") {
        sortDirection = "desc";
    } else {
        if (sortDirection == "asc") sortDirection = "desc";
        else sortDirection = "asc";
    }

    var isPreview = getParameterByName("isPreview") == "1";

    var currentAction = $("form").attr("action");
    if (isPreview) {
        currentAction = currentAction.replace("/ShowResults", "/PreviewResults");
    }
    $("form").attr("action", currentAction + "?sortBy=" + colIndex + "&direction=" + sortDirection);
    $("form").submit();
};
function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
function showDoctorDetails(providerName, providerAddress, providerCity, providerState, providerAddressForGM) {
    clearDialogData();
    $("#spanDoctorName").html(providerName);
    $("#spanAddress").html(providerAddress);
    $("#spanCity").html(providerCity);
    $("#spanState").html(providerState);

    codeAddress(providerAddressForGM);
    $("#dlgProviderMap").dialog("open");
};
function clearDialogData() {
    $("#spanDoctorName").html();
    $("#spanAddress").html();
    $("#spanCity").html();
    $("#spanState").html();
};
function insert_flash(flash_src, flash_width, flash_height, flash_title) {
    document.write('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="' + flash_width + '" height="' + flash_height + '" title="' + flash_title + '"><param name="wmode" value="transparent"/><param name="movie" value="' + flash_src + '" /><param name="quality" value="high" /><embed src="' + flash_src + '" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="' + flash_width + '" height="' + flash_height + '" scale="noborder" wmode="transparent"></embed></object>');
}

function checkemail(str) {
    var filter = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    return filter.test(str);
}

function numbersOnly(evt) {
    evt = (evt) ? evt : window.event;
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode > 31 && (charCode < 48 || charCode > 57)) {
        return false;
    }
    return true;
}

function lettersOnly(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
      ((evt.which) ? evt.which : 0));
    if (charCode > 32 && (charCode < 65 || charCode > 90) &&
      (charCode < 97 || charCode > 122)) {
        return false;
    }
    return true;
}

function isEnterKey(evt) {
    evt = (evt) ? evt : event;
    var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode :
      ((evt.which) ? evt.which : 0));

    if (charCode == 13)
        return true;
    else
        return false;
}

function createBookmark(title, url) {
    if (window.sidebar) { // Mozilla Firefox Bookmark
        window.sidebar.addPanel(title, url, "");
    } else if (window.external) { // IE Favorite
        window.external.AddFavorite(url, title);
    }
    else if (window.opera && window.print) { // Opera Hotlist
        var elem = document.createElement('a');
        elem.setAttribute('href', url);
        elem.setAttribute('title', title);
        elem.setAttribute('rel', 'sidebar');
        elem.click();
    }
}

function init_validate_form(form_name, form_data, error_box) {
    if (error_box == false)
        eval("document." + form_name + ".onsubmit = function() { return validate_form('" + form_name + "', form_data, false, false); } ");
    else
        eval("document." + form_name + ".onsubmit = function() { return validate_form('" + form_name + "', form_data, '" + error_box + "', false); } ");

    eval("var current_form = document." + form_name);
    for (var i = 0; i < current_form.length; i++) {
        for (var j = 0; j < form_data.length; j++) {
            if (current_form[i].name == form_data[j][0]) {
                if (error_box == false)
                    eval("document." + form_name + "." + current_form[i].name + ".onblur = function() { validate_form('" + form_name + "', form_data, false, '" + current_form[i].name + "'); } ");
                else
                    eval("document." + form_name + "." + current_form[i].name + ".onblur = function() { validate_form('" + form_name + "', form_data, '" + error_box + "', '" + current_form[i].name + "'); } ");
            }
        }
    }
}

function validate_form(form_name, temp_form_data, error_box, field_name) {
    var eval_validate_str = "var eval_validate_return = true; ";
    if (error_box != false)
        eval_validate_str += "var error_box_str = document.getElementById('" + error_box + "').innerHTML; ";

    if (field_name != "") {
        for (var j = 0; j < temp_form_data.length; j++) {
            if (temp_form_data[j][0] == field_name) {
                var form_data = new Array();
                form_data[0] = temp_form_data[j]; break;
            }
        }
    }
    else
        var form_data = temp_form_data;

    for (var i = 0; i < form_data.length; i++) {
        if (error_box == false) {
            if (form_data[i][1].indexOf("func:") == 0)
                eval_validate_str += "if (!" + form_data[i][1].replace('func:', '') + "(document." + form_name + "." + form_data[i][0] + ".value)) ";
            else
                eval_validate_str += "if (document." + form_name + "." + form_data[i][0] + "." + form_data[i][1] + ") ";
            eval_validate_str += "{ document.getElementById('" + form_data[i][0] + "_error').innerHTML = '" + form_data[i][2] + "'; eval_validate_return = false } ";
            eval_validate_str += "else document.getElementById('" + form_data[i][0] + "_error').innerHTML = ''; ";
        }
        else {
            eval_validate_str += "error_box_str = error_box_str.replace('" + form_data[i][2] + " <br>', ''); ";
            eval_validate_str += "error_box_str = error_box_str.replace('" + form_data[i][2] + " <BR>', ''); "; //fix ie
            if (form_data[i][1].indexOf("func:") == 0)
                eval_validate_str += "if (!" + form_data[i][1].replace('func:', '') + "(document." + form_name + "." + form_data[i][0] + ".value)) ";
            else
                eval_validate_str += "if (document." + form_name + "." + form_data[i][0] + "." + form_data[i][1] + ") ";
            eval_validate_str += "{ error_box_str += '" + form_data[i][2] + " <br>'; eval_validate_return = false } ";
        }
    }
    if (error_box != false)
        eval_validate_str += "document.getElementById('" + error_box + "').innerHTML = error_box_str";

    eval(eval_validate_str);
    return eval_validate_return;
}

function womGo() {
    for (var i = 0; i < woms.length; i++)
        eval(woms[i]);
}

function womAdd(func) {
    woms[woms.length] = func;
}

var woms = new Array();

window.onload = womGo;

function navinit() {
    $("#nav-yellow").hover(function () {
        var intxt = '';

        $("#nav").css("background", 'url(tpl/ez/images/nav-yellow-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = 'Our Navigators are trained to efficiently direct the consumer to problem solving resources that meet the consumers healthcare needs. The navigator knows the ins and outs of the very complicated healthcare system and can help you find the best, most convenient and lowest cost solutions to your health problems. The navigator does not diagnose or treat health related conditions.';
    },
    function () {
    })

    $("#nav-red").hover(function () {
        var intxt = '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Your Personal Health Record is a private, secure and encrypted version of your health related history, records and data controlled only by you. This information offers you and your selected healthcare professionals access to crucial information to make accurate, effective and timely health decisions.\'); ddrivetip(\'Access Personal Health Record\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 173px 0 0 407px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/>&nbsp; Print (or save) a document summarizing your Personal Health Record (PHR) on your computer or device.\'); ddrivetip(\'Print/Save Summary\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 249px 0 0 311px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/>&nbsp; Send your Personal Health Record electronically to medical providers, or anyone else you chose using secure encrypted transmission.\'); ddrivetip(\'Send Record\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 346px 0 0 245px"></span></a>';
        // intxt += '<a href="#" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/><br/>&nbsp; View and edit your site preferences.\'); ddrivetip(\'My Site Preferences\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 468px 0 0 222px"></span></a>';

        $("#nav").css("background", 'url(tpl/ez/images/nav-red-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = '<br/><br/>&nbsp; This record may include any or all of your personal health information including but not limited to medical records, allergies, medications, genetic information laboratory and imaging studies. You may also include information from your own measurements of vital signs, diet, activity and other self-monitored information.';
    },
    function () {
    })

    $("#nav-orange").hover(function () {
        var intxt = '<a href="providers.php" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; This button provides actual charges and payments for office visits by provider.  As the information becomes available it will also provide objective measures of quality such as the ability to control blood pressure, diabetes or other common conditions.\'); ddrivetip(\'Providers\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 176px 0 0 414px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/>&nbsp; Have information on the published costs for various hospital based procedures.\'); ddrivetip(\'Procedures\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 227px 0 0 321px"></span></a>';
        intxt += '<a href="hospital-rating-metrics.php" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/>&nbsp; Have information on published costs and quality of common hospital based procedures or for the treatment of common conditions within hospital.\'); ddrivetip(\'Hospitals\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 305px 0 0 262px"></span></a>';
        intxt += '<a href="price-comparison" onmouseover="$(\'#navtxt\').html(\'<br/><br/><br/>&nbsp; Compare the relative costs of care between Emergency departments, Urgent care centers and Primary care offices for common non emergency conditions.\'); ddrivetip(\'Price Comparison\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 400px 0 0 227px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'\'); ddrivetip(\'Other Tests\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 505px 0 0 231px"></span></a>';

        $("#nav").css("background", 'url(tpl/ez/images/nav-orange-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = "<br/><br/>&nbsp; Find important objective information on the costs and quality of a large number of medical providers, hospitals, goods and services so that you can make the best choices about how you spend your healthcare dollars.";
    },
    function () {
    })

    $("#nav-green").hover(function () {
        var intxt = '<a href="http://www.americanwell.com/" target="_blank" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Have access to on line secure confidential healthcare providers.\'); ddrivetip(\'Telemedicine\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 198px 0 0 375px"></span></a>';
        intxt += '<a href="online-apps" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; See a vast array of mobile technology applications that can provide monitoring of bodily functions, healthy interventions, and medical information.\'); ddrivetip(\'Online Apps\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 289px 0 0 272px"></span></a>';
        intxt += '<a href="http://www.patientslikeme.com" target="_blank" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; See on line communities focused on wellness or specific medical conditions.\'); ddrivetip(\'Healthy Online Communities\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 418px 0 0 224px"></span></a>';

        $("#nav").css("background", 'url(tpl/ez/images/nav-green-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = "<br/><br/>&nbsp; Find an extensive listing of mobile health applications from telemedicine to self monitoring to on line support communities.";
    },
    function () {
    })

    $("#nav-blue").hover(function () {
        var intxt = '<a href="https://betterdoctor.com/" target="_blank" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Links to the doctor listed in your profile and provides access to online scheduling.\'); ddrivetip(\'With Doctor\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 189px 0 0 377px"></span></a>';
        intxt += '<a href="select-provider" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Pick a provider from the list of regional primary care or specialists and have the ability to make an on line appointment request.\'); ddrivetip(\'Select Provider\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 289px 0 0 272px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Provides access to on line scheduling to providers previously visited.\'); ddrivetip(\'Previous Historical\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 420px 0 0 220px"></span></a>';

        $("#navbg").css("background", 'url(' + navbg + ') no-repeat');
        $("#nav").css("background", 'url(tpl/ez/images/nav-blue-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = "<br/><br/>&nbsp; Have access to local providers and the ability to book an appointment on line.";
    },
    function () {
    })

    $("#nav-purple").hover(function () {
        var intxt = '<a href="your-medications" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Using your personal medications list you can check pricing, renew your meds, get product info, scan additional medication into your list, set up reminders for you to take your medications.\'); ddrivetip(\'Your Medications\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 188px 0 0 376px"></span></a>';
        intxt += '<a href="medication-search" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Search for any medication to find pricing for medications at different pharmacies, order a medication, renew, Get information on different medications, Scan your medications into your records, get reminders for you to take your medications.\'); ddrivetip(\'Medication Search\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 288px 0 0 271px"></span></a>';
        intxt += '<a href="under-construction" onmouseover="$(\'#navtxt\').html(\'<br/><br/>&nbsp; Using the previous search results you can check price, order the medication, renew your medication, and get information about a medication.\'); ddrivetip(\'Medication History\', \'\', \'\', true)" onmouseout="hideddrivetip()"><span style="margin: 417px 0 0 220px"></span></a>';

        $("#nav").css("background", 'url(tpl/ez/images/nav-purple-hover.png) no-repeat');
        $("#doc").hide();
        $("#st").hide();
        document.getElementById("navpos").innerHTML = intxt;
        document.getElementById("navtxt").innerHTML = '<br/><br/>&nbsp; Here you can find pricing for medications at different pharmacies, order a medication,  renew, Get information on different medications, Scan your medications into your records, get reminders for you to take your medications.';
    },
    function () {
    })

    $("#nav").hover(function () {
    },
    function () {
        document.getElementById("nav").style.background = 'url(tpl/ez/images/nav.png) no-repeat';
        $("#doc").show();
        $("#st").show();
        document.getElementById("navpos").innerHTML = "";
        document.getElementById("navtxt").innerHTML = "";

    })
}

womAdd('navinit()');
